<?php defined('InNcPHP') or exit('Access Invalid!');?>

<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js"></script>
<link rel="stylesheet"  type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css">

<style>
    .date{}
    </style>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['order_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!--  搜索表单  -->
    <form method="get" name="formSearch" id="formSearch">
        <input type="hidden" value="bargain_order" name="act">
        <input type="hidden" value="index" name="op">
        <table class="tb-type1 noborder search">
            <tbody>
            <tr>
                <th><label> <?php echo $lang['order_index_order_sn'];?></label></th>
                <td><input type="text" name="search_sn" value="<?php echo $output['search']['search_sn']; ?>" class="txt"></td>
                <th><label><?php echo $lang['order_index_addtime'];?></label></th>
                <td><input type="text" name="search_stime" value="<?php echo $output['search']['search_stime']; ?>" id="search_stime" class="txt date" style="width:110px;"></td>
                <td><input type="text" name="search_etime" value="<?php echo $output['search']['search_etime']; ?>" id="search_etime" class="txt date" style="width:110px;"></td>
            </tr>
            <tr>
                <th><label> <?php echo $lang['order_index_merchant'];?></label></th>
                <td>
                    <select name="search_merchant">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['merchants'])): ?>
                            <?php foreach ($output['merchants'] as $k => $v): ?>
                                <option value="<?php echo $v['merchant_id']; ?>" <?php echo $output['search']['search_merchant'] == $v['merchant_id'] ? 'selected' : ''; ?>><?php echo $v['mc_shop_name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <th><label> <?php echo $lang['order_index_status'];?></label></th>
                <td>
                    <select name="search_status">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['status'])): ?>
                            <?php foreach ($output['status'] as $k => $v): ?>
                                <option value="<?php echo $k; ?>" <?php echo $output['search']['search_status'] == $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <th><label> <?php echo $lang['order_index_type'];?></label></th>
                <td>
                    <select name="order_type">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                         <?php if (is_array($output['type'])): ?>
                            <?php foreach ($output['type'] as $k => $v): ?>

                                <option value="<?php echo $k; ?>" <?php  if(isset($output['search']['order_type']) && $output['search']['order_type'] !=="" ){echo $output['search']['order_type'] == $k ? 'selected' : '';}   ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <td>
                    <a href="javascript:void(0);" onclick="$('#formSearch').submit();" class="btn-search"></a>
                    <?php if ($output['search']['search_sn'] || $output['search']['search_stime'] || $output['search']['search_etime'] || $output['search']['search_merchant'] || $output['search']['search_status']): ?>
                        <a href="index.php?act=bargain_order&op=index" class="btns "><span><?php echo $lang['nc_cancel_search']?></span></a>
                    <?php endif; ?>
                </td>
            </tr>
            </tbody>
        </table>
    </form>

    <div style="text-align:right;"><a class="btns" target="_blank" href="index.php?<?php echo $_SERVER['QUERY_STRING'];?>&op=export"><span><?php echo $lang['nc_export'];?>Excel</span></a></div>
    <!--  显示列表  -->
    <table class="table tb-type2 nobdb">
        <thead>
        <tr class="thead">
            <th><?php echo $lang['order_index_order_sn']?></th>
            <th class="align-center"><?php echo $lang['order_index_title']?></th>
            <th class="align-center"><?php echo $lang['order_index_nickname']?></th>
            <th class="align-center"><?php echo $lang['order_index_merchant']?></th>
            <th class="align-center"><?php echo $lang['order_index_money']; ?></th>
            <th class="align-center"><?php echo $lang['order_index_addtime'];?></th>
            <th class="align-center"><?php echo $lang['order_index_status']?></th>
            <th class="align-center"><?php echo $lang['order_index_type']?></th>
            <th class="align-center"><?php echo $lang['nc_handle'];?></th>
        </tr>
        <tbody>
        <?php if(!empty($output['bargain_order_list']) && is_array($output['bargain_order_list'])){ ?>
            <?php foreach($output['bargain_order_list'] as $k => $v){ ?>
                <tr class="hover member">
                    <td><?php echo $v['bg_order_sn']; ?></td>
                    <td class="align-center"><?php echo $v['bg_title']; ?></td>
                    <td class="align-center"><?php echo $v['nickname']; ?></td>
                    <td class="align-center"><?php echo $v['mc_shop_name']; ?></td>
                    <td class="align-center"><?php echo $v['bg_order_price']; ?></td>
                    <td class="align-center"><?php echo date('Y-m-d H:i:s',$v['add_time']); ?></td>
                    <td class="align-center"><?php echo $output['status'][$v['bg_order_status']]; ?></td>
                    <td class="align-center"><?php echo $output['type'][$v['type']]; ?></td>
                    <td class="align-center">
                        <?php if($v['bg_order_status'] == 20 && $v['type'] == 0){?>
                        <a href="###" onclick="handle(<?php echo $v['bg_order_id']?>)">发货</a>
                        <?php }?>
                        <a href="index.php?act=bargain_order&op=bg_orde_info&bg_order_id=<?php echo $v['bg_order_id']; ?>">查看</a>
                    </td>
                </tr>
            <?php } ?>
        <?php }else { ?>
            <tr class="no_data">
                <td colspan="11"><?php echo $lang['nc_no_record']?></td>
            </tr>
        <?php } ?>
        </tbody>
        <tfoot class="tfoot">
        <?php if(!empty($output['bargain_order_list']) && is_array($output['bargain_order_list'])){ ?>
            <tr>
                <td colspan="16">
                    <div class="pagination"> <?php echo $output['page'];?> </div>
                </td>
            </tr>
        <?php } ?>
        </tfoot>
    </table>
</div>


<!-- 处理表单 -->
<form id="handle" style="display: none;">

    <table class="table tb-type2">
        <tbody>

        <!-- 处理人 -->
        <tr>
            <td colspan="2" class="required">
                <label>物流单号: </label>
                <input type="text" name="logistics_no">
            </td>
        </tr>
        <!-- 处理备注 -->
        <tr>
            <td colspan="2" class="required">
                <label>物流公司: </label>
                <input type="text" name="dhl">
            </td>
        </tr>
        </tbody>
        <tfoot>
        <tr>
            <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="handle_btn"><span>发货</span></a></td>
            <input type="hidden" name="bg_order_id">
        </tr>
        </tfoot>
    </table>
</form>

<script>
    $('#search_stime').datetimepicker({
        controlType: 'select'
    });

    $('#search_etime').datetimepicker({
        controlType: 'select'
    });

    //处理函数
    function handle(id) {
        var form = $('#handle');
        $("[name='bg_order_id']").val(id);
        layer.open({
            type: 1,
            title: '发货',
            area: ['400px', '300px'],
            content: form,
            cancel: function () {

            }
        });

    }
    //点击发货
    $("#handle_btn").click(function(){
        if($("[name='logistics_no']").val()=='' || $("[name='dhl']").val()==''){
            alert('请将发货信息填写完整！');
            return false;
        }
        $.post('index.php?act=bargain_order&op=Shipping', $('#handle').serialize(), function (ret) {
            if (ret.datas) {
                layer.alert('更新成功', function () {
                    location.reload();
                });
            } else {
                layer.alert('更新失败');
            }
        }, 'json');

    })
</script>
